package cn.source.system.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import cn.source.system.mapper.AaBannerDaoMapper;
import cn.source.system.response.ApiBannerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.source.system.mapper.AaBannerMapper;
import cn.source.system.domain.AaBanner;
import cn.source.system.service.IAaBannerService;

/**
 * bannerService业务层处理
 * 
 * @author sourcebyte.vip
 * @date 2023-08-04
 */
@Service
public class AaBannerServiceImpl implements IAaBannerService 
{
    @Autowired
    private AaBannerMapper aaBannerMapper;

    @Autowired
    private AaBannerDaoMapper aaBannerDaoMapper;

    /**
     * 查询banner
     * 
     * @param id banner主键
     * @return banner
     */
    @Override
    public AaBanner selectAaBannerById(Long id)
    {
        return aaBannerMapper.selectAaBannerById(id);
    }

    /**
     * 查询banner列表
     * 
     * @param aaBanner banner
     * @return banner
     */
    @Override
    public List<AaBanner> selectAaBannerList(AaBanner aaBanner)
    {
        return aaBannerMapper.selectAaBannerList(aaBanner);
    }

    /**
     * 新增banner
     * 
     * @param aaBanner banner
     * @return 结果
     */
    @Override
    public int insertAaBanner(AaBanner aaBanner)
    {
        return aaBannerMapper.insertAaBanner(aaBanner);
    }

    /**
     * 修改banner
     * 
     * @param aaBanner banner
     * @return 结果
     */
    @Override
    public int updateAaBanner(AaBanner aaBanner)
    {
        return aaBannerMapper.updateAaBanner(aaBanner);
    }

    /**
     * 批量删除banner
     * 
     * @param ids 需要删除的banner主键
     * @return 结果
     */
    @Override
    public int deleteAaBannerByIds(Long[] ids) {
        int count = 0;
        for (int i = 0; i < ids.length; i++) {
            AaBanner banner = selectAaBannerById(ids[i]);
            if (ObjectUtil.isNotEmpty(banner)) {
                banner.setDelFlag(1);
                count += aaBannerMapper.updateAaBanner(banner);
            }
        }
        return count;
//        return aaBannerMapper.deleteAaBannerByIds(ids);
    }

    /**
     * 删除banner信息
     * 
     * @param id banner主键
     * @return 结果
     */
    @Override
    public int deleteAaBannerById(Long id)
    {
        return aaBannerMapper.deleteAaBannerById(id);
    }

    @Override
    public List<ApiBannerResponse> apiBannerList() {
        return aaBannerDaoMapper.bannerList();
    }
}
